interface Command {
    execute(): void
}

class Light {
    turnOn() {
        console.log("开灯");
    }
    turnOff() {
        console.log("关灯");
    }
}

class TurnOnCommand implements Command {
    declare private _light: Light
    constructor(light: Light) {
        this._light = light
    }
    execute(): void {
        this._light.turnOn()
    }

}
class TurnOffCommand implements Command {
    declare private _light: Light
    constructor(light: Light) {
        this._light = light
    }
    execute(): void {
        this._light.turnOff()
    }

}
class Control {
    declare private _command: Command
    setCommand(cmd: Command) {
        this._command = cmd
    }
    execute() {
        this._command.execute()
    }
}


const light = new Light()
const control = new Control()
control.setCommand(new TurnOnCommand(light))
control.execute()

control.setCommand(new TurnOffCommand(light))
control.execute()